unit resetform;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, BCButton, BCLabel, BGRALabel, Forms, Controls,
  Graphics, Dialogs, ExtCtrls, StdCtrls, nkTitleBar;

type

  { TfrmReset }

  TfrmReset = class(TForm)
    BCButton1: TBCButton;
    BCLabel1: TBCLabel;
    cg: TCheckGroup;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TBGRALabel;
    Label5: TLabel;
    Label6: TLabel;
    nkTitleBar1: TnkTitleBar;
    Panel1: TPanel;
    Panel3: TPanel;
    Panel8: TPanel;
    procedure BCButton1Click(Sender: TObject);
    procedure BCLabel1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Image2MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Image2MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer
      );
    procedure Image2MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    Moving:boolean;
    XPos,YPos:integer;
  public

  end;

var
  frmReset: TfrmReset;

implementation

uses
  datamodule;
{$R *.frm}

{ TfrmReset }

procedure TfrmReset.FormShow(Sender: TObject);
begin
  Label4.Caption:=Dm.Platform;
end;

procedure TfrmReset.Image2MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if mbLeft = Button then
  begin
    Self.Moving:=True;
    Self.YPos := Y;
    Self.XPos := X;
  end;
end;

procedure TfrmReset.Image2MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  if not (csDesigning in Self.ComponentState) then
  begin
    if Self.Moving then
    begin
      Self.Top:=Self.Top+Y-Self.YPos;
      Self.Left:=Self.Left+X-Self.XPos;
      if Self.Top<0 then
        Self.Top:=0;
    end;
  end;
end;

procedure TfrmReset.Image2MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  Moving:=False;
end;

procedure TfrmReset.BCButton1Click(Sender: TObject);
var
  i:integer;
  mselected:boolean;
begin
  //清除数据库，先检查是否有选中项目
  mselected:=False;
  for i:=0 to cg.Items.Count-1 do
  begin
    mselected:=mselected or cg.Checked[i];
  end;
  if mselected = False then
  begin
    MessageDlg('请先选中要复位的数据项目！',mtInformation,[mbOK],0);
    Exit;
  end;
  Label5.Caption:='开始复位……';
  BcButton1.Enabled:=False;
  Application.ProcessMessages;
  if cg.Checked[0] then
  begin
    //职工医疗个人账户划拨数据
    Label5.Caption:='正在复位职工医疗个人账户划拨数据……';
    Label5.Update;
    Application.ProcessMessages;
    Dm.ResetTable('huabo');
  end;
  if cg.Checked[1] then
  begin
    //死亡人口名单
    Label5.Caption:='正在复位死亡人口数据……';
    Label5.Update;
    Application.ProcessMessages;
    Dm.ResetTable('siwang');
  end;
  if cg.Checked[2] then
  begin
    //单位信息表
    Label5.Caption:='正在复位单位信息数据……';
    Label5.Update;
    Application.ProcessMessages;
    Dm.ResetTable('danwei');
  end;
  if cg.Checked[3] then
  begin
    //企业注销登记
    Label5.Caption:='正在复位企业注销信息数据……';
    Label5.Update;
    Application.ProcessMessages;
    Dm.ResetTable('zhuxiao');
  end;
  if cg.Checked[4] then
  begin
    //风险分析报告
    Label5.Caption:='正在复位风险分析报告数据……';
    Label5.Update;
    Application.ProcessMessages;
    Dm.ResetTable('huabofx');
  end;
  if cg.Checked[5] then
  begin
    //数据大屏相关状态
    Label5.Caption:='正在复位数据大屏状态数据……';
    Label5.Update;
    Application.ProcessMessages;
    Dm.ResetBigData;
  end;
  if cg.Checked[6] then
  begin
    //风险分析日志
    Label5.Caption:='正在复位风险分析日志数据……';
    Label5.Update;
    Application.ProcessMessages;
    Dm.ResetTable('anallog');
  end;
  if cg.Checked[7] then
  begin
    //数据导入日志
    Label5.Caption:='正在复位数据导入日志数据……';
    Label5.Update;
    Application.ProcessMessages;
    Dm.ResetTable('importlog');
  end;
  Label5.Caption:='完成复位';
  BcButton1.Enabled:=True;
  Application.ProcessMessages;
end;

procedure TfrmReset.BCLabel1Click(Sender: TObject);
begin
  ModalResult:=mrCancel;
end;

end.

